;
(function() {
	module.exports = {
		//增加运费模板
		addExpress: function(new_express_info) {
			new_express_info.bus_id = this._id;
			var new_express = new ExpressCon(new_express_info);
			var express_list = this._getExpressList();
			express_list.unshift(new_express._id);
			this.save();
			return new_express;
		},
		//代码片段，获取Express对象
		_getExpress: function(express_id) {
			var express_list = this._getExpressList();
			if (express_list.indexOf(express_id) === -1) {
				throwCusError("运费模板不属于指定商家")
			}
			var express = ExpressCon.get(express_id);
			if (!express) {
				throwCusError("找不到指定运费模板");
			}
			return express;
		},
		_getExpressList: function() {
			var express_list = this.express_list;
			if (!express_list) {
				express_list = this.express_list = [];
				this.save();
			}
			return express_list;
		},
		//获取运费模板详细信息
		getExpressList: function(num, page, filter) {
			var self = this;
			var express_list = self._getExpressList();
			if (filter) {
				var result = [];
				express_list.forEach(function(express_id) {
					var ach = ExpressCon.get(express_id)
					if (filter(ach)) {
						result.push(ach);
					}
				});
				result = data_cut.page(result, num, page)
			} else {
				express_list = data_cut.page(express_list, num, page);
				result = express_list.map(function(express_id) {
					return ExpressCon.get(express_id);
				});
			}
			return result;
		},
		updateExpress: function(express_id, express_info) {
			var express = this._getExpress(express_id);
			express.setInfo(express_info);
			return express;
		},
		removeExpress: function(express_id) {
			var express = this._getExpress(express_id);
			this.express_list = $Array.remove(this._getExpressList(), express_id);
			this.save();
			express.destroy();
		}
	};
	var db = require("../db/index");
	var DomainCon = require("../domain/_con");
	var GoodsCon = require("../goods/_con");
	var UserCon = require("../../core/user/_con");
	var BusCon = require("../../core/bus/_con");
	var AchCon = require("../ach/_con");
	var ExpressCon = require("../bus.express/_con");
	var ClassifyCon = require("../bus.classify/_con");
	var TagCon = require("../bus.tag/_con");
	var LeagueCon = require("../league/_con");
	var BuffCon = require("../buff/_con");
	var BusUserBindCon = require("../bus_user_bind/_con");
	var BusGuideCon = require("../bus.guide/_con");
	var CommentCon = require("../comment/_con");
	var config = require("../_include/config");
	var data_cut = require("../_include/data_cut");
	var helper = require("../_include/helper");
	var md5 = require("../_include/md5");
	var $Object = require("../_include/$.Object");
	var $Array = require("../_include/$.Array");
	var tld = require('tldjs');
	var fs = require("fs");
	var Fiber = require('fibers');
}());